/*use cassie_core::config::config::ApplicationConfig;
use cassie_core::fundation::{AppContext, ApplicationContext};
use cassie_core::security::casbin::rhai::ImmutableString;
use cassie_core::security::casbin::{CachedEnforcer, CoreApi, DefaultModel};
use cassie_core::security::middleware::CasbinService;
use mapper::adapter::SeaOrmAdapter;
use log::info;
use std::sync::Arc;
use tokio::sync::RwLock;
/**
*description:根据路径初始化系统配置
*author:cassie-lxd<348040933@qq.com>
*/
pub async fn init_authservice() {
  let casbin_service = init_casbin_service(MODEL_AUTH).await;
  match casbin_service {
    None => {}
    Some(service) => ApplicationContext::set_service(service),
  }
}

pub async fn init_casbin_service(auth_str: &str) -> Option<CasbinService> {
  let c = ApplicationContext::get_service::<ApplicationConfig>();
  if let Some(cof) = c {
    let config = cof.lock().unwrap();
    let m = DefaultModel::from_str(auth_str).await.unwrap();
    let adapter = SeaOrmAdapter::new(config.database_url(), false).await.expect("open db error");
    let mut enforcer: CachedEnforcer = CachedEnforcer::new(m, adapter).await.unwrap();
    enforcer.add_function("ciciMatch", cici_match);
    let casbin_service = CasbinService::set_enforcer(Arc::new(RwLock::new(enforcer)));
    return Some(casbin_service);
  }
  return None;
}

pub fn cici_match(user: ImmutableString, path: ImmutableString) -> bool {
  info!("{}:{}", user, path);

  return true;
}

const MODEL_AUTH: &str = r#"
         [request_definition]
        r = sub, dom, obj, act

        [policy_definition]
        p = sub, dom, obj, act

        [role_definition]
        g = _, _, _

        [policy_effect]
        e = some(where (p.eft == allow))

        [matchers]
        m = ciciMatch(r.sub,r.obj) || (g(r.sub, p.sub, r.dom) && r.dom == p.dom && keyMatch2(r.obj, p.obj) && r.act == p.act)
"#;
*/
